他的型別只能是UInt64與UInt32所以運算是負數的話會是錯的,最小的值只能是0
do {
let encryptParams =
try EncryptionParameters<Bfv<UInt64>>(from: .insecure_n_8_logq_5x18_logt_5)
let context = try Context(encryptionParameters: encryptParams)
let values1: [UInt64] = [8, 5, 12, 12, 15, 5, 6, 7]
let values2: [UInt64] = [1, 2, 3, 4, 5, 6, 7, 8]
let plaintext1: Bfv<UInt64>.CoeffPlaintext = try context.encode(values: values1, format: .coefficient)
let plaintext2: Bfv<UInt64>.CoeffPlaintext = try context.encode(values: values2, format: .coefficient)
let secretKey = try context.generateSecretKey()
let ciphertext1 = try plaintext1.encrypt(using: secretKey)
let ciphertext2 = try plaintext2.encrypt(using: secretKey)
let encryptedSum = try ciphertext1.convertToEvalFormat() - ciphertext2.convertToEvalFormat()
print("encryptedSum" , encryptedSum)
print(try encryptedSum.decrypt(using: secretKey))
} catch {
return
}
注意他只能在執行在 mac os 上在iOS上是不行的